//
//  SSMineHeaderView.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/2/9.
//

import UIKit

class SSMineHeaderView: UIView {

    var user = SSUser()
    
    @IBOutlet weak var checkInfoLab: UILabel!
    @IBOutlet weak var userName: UILabel!
    @IBOutlet weak var infoBG: UIView!

    @IBOutlet weak var loginLab: UILabel!
    @IBOutlet weak var couponImage: UIImageView!
    
    @IBOutlet weak var purseImageV: UIImageView!
    class func headerView()->SSMineHeaderView{
        return Bundle.main.loadNibNamed("SSMineHeaderView", owner: nil, options: nil)?.last as! SSMineHeaderView
    }
    
    ///init方法，纯代码创建时调用
    override init(frame: CGRect) {
        super.init(frame: frame)
//        setupUI()
    }
    
    
    //init方法，通过xib创建时调用
    required init?(coder: NSCoder) {
        super.init(coder: coder)
//        setupUI()
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setupUI()
    }
    
    
    
    func setupUI (){
        
        infoBG.layer.cornerRadius = 8
        infoBG.layer.masksToBounds = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(tapClick))
        couponImage.addGestureRecognizer(tap)
        couponImage.isUserInteractionEnabled = true
        
        let tap2 = UITapGestureRecognizer.init(target: self, action: #selector(purseClick))
        purseImageV.addGestureRecognizer(tap2)
        purseImageV.isUserInteractionEnabled = true
        
        let tap1 = UITapGestureRecognizer.init(target: self, action: #selector(infoClick))
        infoBG.addGestureRecognizer(tap1)
        infoBG.isUserInteractionEnabled = true
        
    }
    
    @objc func infoClick() {
        
        if !kIsLogin {
            kNotifiDefault.post(name: .AppShowLoginController, object: nil)
            return
        }
        
        let sb = UIStoryboard(name: "SSSetupMineInfoViewController", bundle: nil)
        let vc = sb.instantiateInitialViewController() as! SSSetupMineInfoViewController
        vc.user = self.user
        UIViewController.current().navigationController?.pushViewController(vc, animated: true)

    }
    
    @objc func purseClick() {
        if !kIsLogin {
            kNotifiDefault.post(name: .AppShowLoginController, object: nil)
            return
        }
        print("123")
        let vc = SSMyPurseViewController.init()
        UIViewController.current().navigationController?.pushViewController(vc, animated: true)
    }
    
    @objc func tapClick() {
        if !kIsLogin {
            kNotifiDefault.post(name: .AppShowLoginController, object: nil)
            return
        }
        print("123")
        let vc = SSMyCouponController.init()
        UIViewController.current().navigationController?.pushViewController(vc, animated: true)
    }
    
    func setData(user:SSUser) {
        
        if !kIsLogin {
            loginLab.isHidden = false
            userName.isHidden = true
            checkInfoLab.isHidden = true
            return
        }
        loginLab.isHidden = true
        userName.isHidden = false
        checkInfoLab.isHidden = false
        
        self.user = user
        userName.text = user.userName
        
    }
}
